package cn.szzsi._admin;

import cn.szzsi.common.bean.dto.Msg;
import cn.szzsi.common.kit.CommonUtil;
import cn.szzsi.common.model.VersionRecord;
import com.jfinal.aop.Clear;
import com.jfinal.kit.Ret;
import com.jfinal.kit.StrKit;

import java.util.Date;
import java.util.List;

/**
 * Created by zhengy on 2017/2/17.
 * 商户后台类-版本记录
 */
public class VersionRecordController extends BaseAdminController<VersionRecord> {
    private VersionRecord versionRecord;
    //展示系统更新日志
    @Clear
    public void index(){
        List<VersionRecord> versionRecord= VersionRecord.dao.find("select DATE_FORMAT(createDate,'%Y年%m月%d日')ymd,DATE_FORMAT(createDate,'%H:%i')time,DAYOFWEEK(createDate)-1 week,content from mall_version_record order by createDate desc");
        renderJson(Msg.success(versionRecord));
    }

    public void list(){
        render(CommonUtil.TEMPLATE_PATH+"/business/versionrecord/version_record_list.html");

    }
    //ajax list
    public void ajaxlist(){
        List<VersionRecord> lvr = VersionRecord.dao.find("select * from mall_version_record order by createDate desc");
        renderJson(lvr);
    }
    // 添加
    public void add(){
        render(CommonUtil.TEMPLATE_PATH+"/business/versionrecord/version_record_input.html");
    }
    public void save(){
        versionRecord=getModel(VersionRecord.class);
        versionRecord.set("createDate",new Date());
        versionRecord.save();
        renderJson(Ret.ok("info","添加成功!").set("url","list"));
        //redirect("/shop/versionrecord/list");

    }
    public void edit(){
        String id = getPara("id","");
        if (StrKit.notBlank(id)){
            setAttr("versionRecord", VersionRecord.dao.findById(id));
        }
        render(CommonUtil.TEMPLATE_PATH+"/business/versionrecord/version_record_input.html");
    }
    public void update(){
        versionRecord=getModel(VersionRecord.class);
        versionRecord.update();
        renderJson(Ret.ok("info","修改成功!").set("url","list"));
        //redirect("/shop/versionrecord/list");
    }
    public void delete(){
        String id=getPara("id");
        VersionRecord.dao.deleteById(id);
        renderJson(Ret.ok());
    }
}
